const MY = {



	imgurl: '', // 图片拼接地址
	// url: "http://netsea.cougogo.com",
	url: "https://netsea.aucfan-cn.com",
	phone_type: uni.getSystemInfoSync().platform,
	hidephone: function(phone) {
		if (!phone) return
		return phone.substring(0, 3) + "****" + phone.substring(7)
	},
	isVideo(val) {
		if (val) {
			val = val + ''
			return val.includes('.mp4')
		}
	},
	copy(value) {
		let _this = this;
		uni.setClipboardData({
			data: String(value), // e是你要保存的内容
			success: function() {
				uni.showToast({
					title: '复制成功',
					icon: 'none'
				})
			}, 
			fail: function() {
				_this.toast('复制失败，稍后再试试吧')
			}
		})
	},

  delete:function(callBack){
	  uni.showModal({
	  	title: "",
	  	content: "确定要删除吗",
	  	cancelText: '取消', // 取消按钮的文字   
	  	confirmText: '确认', // 确认按钮的文字   
	  	success: function(res) {
	  		if (res.confirm) {
	  			uni.showLoading({
	  				title: '删除中'
	  			})
	  			// callBack
	  		}
	  	}
	  })
  },
	post: function(url, datas) {
		return new Promise(resolve => {
			uni.request({
				url: this.url + url,
				data: datas,
				method: 'POST',
				dataType: "json",
				header: {
					"Accept-Language": uni.getStorageSync('locale') == 'ko' ? 'kor' : uni
						.getStorageSync('locale') ? uni.getStorageSync('locale') : 'zh',
					"lang": uni.getStorageSync('locale') == 'ko' ? 'kor' : uni.getStorageSync(
						'locale') ? uni.getStorageSync('locale') : 'zh',
					'token': uni.getStorageSync('token'),
					'Content-Type': "application/x-www-form-urlencoded; application/json",
					'x-requested-with': 'XMLHttpRequest',
					// 'cookie':uni.getStorageSync('SetCookie')//自定义请求头信息
				},
				success: ({
					data,
					header
				}) => {
					if (data.code === 204) uni.reLaunch({
						url: '/pages/login/login'
					})
					// this.toast('网络请求失败')
					// uni.setStorageSync('SetCookie',header['Set-Cookie'])
					resolve(data)
				},
				fail: () => {
					this.toast('网络请求失败')
				},
				complete: () => {
					// uni.hideLoading()
				}
			})
		})

	},
	// 查看大图
	previewImage:function(imgs){
		uni.previewImage({
			urls: imgs,
		});
	},
	get: function(url, datas) {
		return new Promise(resolve => {
			uni.request({
				url: this.url + url,
				data: datas || {},
				method: 'GET',
				dataType: "json",
				header: {
					"Accept-Language": uni.getStorageSync('locale') == 'ko' ? 'kor' : uni
						.getStorageSync('locale') ? uni.getStorageSync('locale') : 'zh',
					"lang": uni.getStorageSync('locale') == 'ko' ? 'kor' : uni.getStorageSync(
						'locale') ? uni.getStorageSync('locale') : 'zh',
					'token': uni.getStorageSync('token'),
					'Content-Type': "application/x-www-form-urlencoded; application/json",
					'x-requested-with': 'XMLHttpRequest',
				},
				success: ({
					data,
					header
				}) => {
					if (data.code === 204) uni.reLaunch({
						url: '/pages/login/login'
					})

					resolve(data)
				},
				fail: () => {
					this.toast('网络请求失败')
				},
				complete: () => {
					// uni.hideLoading()
				}
			})
		})
	},



	choosepic: function(val) {
		if (this.phone_type == 'ios') {
			return new Promise(resolve => {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera '], //手机拍照
					success: (res) => {
						const tempFilePaths = res.tempFilePaths;
						// if (res.tempFiles[0].size > 2291456) return uni.showToast({title: "上传图片大小不能超过2MB",icon: 'none'});
						console.log(tempFilePaths[0], 852741)
						uni.uploadFile({
							url: this.url + val,
							filePath: tempFilePaths[0],
							name: 'file',
							header: {
								"Accept-Language": uni.getStorageSync('locale') ?
									uni.getStorageSync('locale') : 'zh',
								'token': uni.getStorageSync('token'),
							},
							formData: {
								use: 'company_photo'
							},
							success: (uploadFileRes) => {
								let res = JSON.parse(uploadFileRes.data);
								if (res.code == 200) {
									this.toast(res.message)
									resolve(res.data)
								} else {
									this.toast(res.message)
								}
							}
						});
					}
				});
			})
		} else {
			return new Promise(resolve => {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //手机拍照
					success: (res) => {
						const tempFilePaths = res.tempFilePaths;
						// if (res.tempFiles[0].size > 2291456) return uni.showToast({title: "上传图片大小不能超过2MB",icon: 'none'});
						console.log(tempFilePaths[0], 852741)
						uni.uploadFile({
							url: this.url + val,
							filePath: tempFilePaths[0],
							name: 'file',
							header: {
								"Accept-Language": uni.getStorageSync('locale') ?
									uni.getStorageSync('locale') : 'zh',
								'token': uni.getStorageSync('token'),
							},
							formData: {
								"file": tempFilePaths[0],
								use: 'company_photo'
							},
							success: (uploadFileRes) => {
								let res = JSON.parse(uploadFileRes.data);
								if (res.code == 200) {
									this.toast(res.message)
									resolve(res.data)
								} else {
									this.toast(res.message)
								}
							}
						});
					}
				});
			})
		}

	},

	// 姓名隐藏名
	hideName(name) {
		if (!name) return;
		let name1 = name;
		if (name.length == 2) {
			name1 = name.substring(0, 1) + "*";
		} else if (name.length == 3) {
			name1 = name.substring(0, 1) + "**";
		} else if (name.length == 4) {
			name1 = name.substring(0, 1) + "***";
		} else if (name.length == 5) {
			name1 = name.substring(0, 1) + "****";
		}
		return name1;
	},


	go(url, time = 0) {
		if (!url) {
			setTimeout(() => {
				uni.navigateBack({
					delta: 1
				})
			}, time)
		} else {
			setTimeout(() => {
				uni.navigateTo({
					url
				})
			}, time)
		}
	},
	toast: function(msg) {
		// #ifndef APP-PLUS
		uni.showToast({
			title: msg,
			icon: "none"
		})
		// #endif
		// #ifdef APP-PLUS
		void plus.nativeUI.toast(msg, {
			background: 'rgba(0,0,0,.4)',
			verticalAlign: 'center',
			duration: 'short'
		});
		// #endif
	},
	//防抖
	dou: function() {
		let timer = null;
		return function(callback, delayed) {
			clearTimeout(timer)
			timer = setTimeout(() => {
				callback()
			}, delayed)
		}
	},
	//节流
	shollte: function() {
		let flag = true
		return function(callback, delayed) {
			if (flag) {
				callback()
				flag = false
				setTimeout(() => {
					flag = true
				}, delayed)
			}
		}
	},
}






export default MY
